class Solution
{
public:
    int alternateDigitSum(int n)
    {
        int result = 0;
        int digitCount = 0;
        while (n)
        {
            if (digitCount & 1)
            {
                result += n % 10;
            }
            else
            {
                result -= n % 10;
            }
            ++digitCount;
            n /= 10;
        }
        if (digitCount & 1)
        {
            result = -result;
        }
        return result;
    }
};